package leetcode.weekly.week297;

//Solution1Test 
public class Solution1 {

	// Solution1Test
	public double calculateTax(int[][] brackets, int income) {
		double ans = 0;
		int p = 0;
		while (income > 0) {
			int[] cur = brackets[p];
			int upper = cur[0];
			int percent = cur[1];
			int num = 0;
			if (p == 0) {
				num = upper;
			} else {
				num = upper - brackets[p - 1][0];
			}
			if (income >= num) {
				ans += 1d * num * percent / 100;
			} else {
				ans += 1d * income * percent / 100;
			}
			income -= num;
			p++;
		}
		return ans;
	}

}
